<template>
	<view class="">
		<view class="" :style="'height: '+statusBarHeight+'px;'"></view>
		<view class="" style="height: 248rpx;"></view>
		<view class="boxcenter">
			<view class="boxcenter_name">
				登录万寿园
			</view>
			<view class="labeltext">
				<input type="text" v-model="username" @input='inputChange' placeholder="请输入用户名"
					placeholder-class="phone" />
			</view>

			<view class="labeltext">
				<input v-if="!isshow" type="password" v-model="password" @input='inputChange' placeholder="请输入密码"
					placeholder-class="password" />
				<input v-else type="text" v-model="password" @input='inputChange' placeholder="请输入密码"
					placeholder-class="password" />
				<image :src="isshow?'/static/show.png':'/static/noshow.png'" mode="" @click="isshow=!isshow">
				</image>
			</view>
			<view :class="logining?'isbtn istext':'istext'" @click="logining?$u.throttle(toLogin, 500):''">
				立即登录
			</view>
			<view class="nologin flex-between">
				<view class="" @click="$fun.jump('./register')">
					注册账号
				</view>
				<!-- <view class="" @click="$fun.jump('./find')">
					忘记密码
				</view> -->
			</view>
			<view class="" style="display: flex;justify-content: space-around;">
				<view class="agree">
					<image :src="isCh?'/static/sel.png':'/static/sel1.png'" mode="" @click="isCh=!isCh"></image>
					<view class="">
						我已阅读并同意 <span
							@click="$fun.jump('/pageA/noticeList/noticeInfo?name=用户政策&type=16')">《用户服务协议》</span>
						<span @click="$fun.jump('/pageA/noticeList/noticeInfo?name=隐私政策&type=15')">《隐私政策》</span>
					</view>
				</view>
			</view>
		</view>
		<!-- #ifdef H5 -->
		<view class="dowload" @click="dow" v-if="configObj.download_address">下载APP</view>
		<!-- #endif -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: 0,
				logining: false,
				username: '',
				password: '',
				isCh: false,
				isshow: false,
				configObj: {}
			}
		},
		onLoad(options) {
			if (options.adminMobile) {
				this.username = options.adminMobile
				this.password = options.adminPassword
				this.inputChange()
			}
			this.$fun.ajax.post('index/config', {}).then(res => {
				// this.loginList = res.data.login
				this.configObj = res.data
			})
		},
		onShow() {
			const phoneInfo = uni.getSystemInfoSync(); // 获取手机系统信息
			this.statusBarHeight = phoneInfo.statusBarHeight
		},
		methods: {
			dow() {
				location.href = this.configObj.download_address
			},
			inputChange() {
				const {
					username,
					password,
				} = this;
				if (username !== '' && password !== '') {
					this.logining = true
				} else {
					this.logining = false
				}
			},
			async toLogin() {
				if (this.isClick) {
					return
				}
				const {
					username,
					password
				} = this;
				if (!this.isCh) {
					this.$fun.msg('请先同意用户协议和隐私协议');
					return
				}
				// 手机号为空
				if (!username) {
					this.$fun.msg('请输入用户名');
					return
				}
				// 密码为空
				if (!password) {
					this.$fun.msg('请输入密码');
					return
				}
				this.isClick = true
				const sendData = {
					account: username,
					password: password,
				};
				const result = await this.$fun.ajax.post('user/login', sendData);
				console.log(result)
				if (result.code === 1) {
					let ispush = true
					let arr = uni.getStorageSync('userCode') ? JSON.parse(uni.getStorageSync('userCode')) : [];
					if (arr.length == 0) {
						arr.push({
							account: username,
							password: password,
							avatar: result.data.userinfo.avatar
						})
					}
					for (var i = 0; i < arr.length; i++) {
						if (arr[i].account == username) {
							ispush = false
						}
					}
					if (ispush) {
						arr.push({
							account: username,
							password: password,
							avatar: result.data.userinfo.avatar
						})
					}
					uni.setStorageSync('userCode', JSON.stringify(arr))
					this.isClick = false
					uni.setStorageSync('token', result.data.userinfo.token)
					this.$fun.msg(result.msg)
					this.$fun.jump('/pages/index/index', 3, 1200)
				} else {
					this.isClick = false
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		background-image: url('/static/bg@2x.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
	}

	.boxcenter {
		width: 640rpx;
		height: 768rpx;
		background: #FFFFFF;
		border-radius: 40rpx;
		margin: 0 auto 0;
		padding: 100rpx 40rpx 30rpx;
		box-sizing: border-box;

		&_name {
			font-family: PingFangSC, PingFang SC;
			font-weight: bold;
			font-size: 40rpx;
			color: #19181A;
			text-align: center;
			font-style: normal;
			margin-bottom: 60rpx;
		}

		.labeltext {
			width: 560rpx;
			height: 96rpx;
			background: #F2F2F2;
			border-radius: 48rpx;
			padding-bottom: 20rpx;
			display: flex;
			align-items: center;
			padding-left: 30rpx;
			padding-top: 18rpx;
			box-sizing: border-box;
			margin-top: 30rpx;
			padding-right: 30rpx;
			justify-content: space-between;

			image {
				width: 48rpx;
				height: 48rpx;
			}

			&_code {
				font-weight: 500;
				font-size: 28rpx;
				color: #ED4961;
				line-height: 96rpx;
				font-style: normal;
				margin-right: 30rpx;
			}

			.istipcol {
				color: #999999;
			}
		}

		.phone,
		.password {
			background: #F2F2F2;
			border-radius: 48rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #999999;
			text-align: left;
			font-style: normal;
		}

		.nologin {
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #ED4961;
			text-align: center;
			font-style: normal;
			margin-top: 30rpx;
		}

		.flex-between {
			display: flex;
			justify-content: space-between;
		}
	}

	.dowload {
		font-size: 24rpx;
		color: #ED4961;
		text-align: center;
		margin-top: 10rpx;
	}

	.istext {
		width: 560rpx;
		height: 96rpx;
		border-radius: 48rpx;
		background-color: #F2F2F2;
		text-align: center;
		line-height: 96rpx;
		margin-top: 30rpx;
		color: #CCCCCC;
	}

	.isbtn {
		background: $uni-color-primary;
		color: #FFFFFF;
	}

	.agree {
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #313233;
		line-height: 33rpx;
		text-align: center;
		font-style: normal;
		display: flex;
		margin-top: 62rpx;

		image {
			width: 36rpx;
			height: 36rpx;
			margin-right: 16rpx;
		}

		span {
			color: #ED4961;
		}
	}
</style>